package com.sisyphus.simple.activities;

import android.os.Bundle;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sisyphus.simple.R;
import com.sisyphus.simple.SimpleAppActivityListTemplate;
import com.sisyphus.simple.adapters.PostListAdapter;
import com.sisyphus.simple.data.DataRepository;
import com.sisyphus.simple.data.network.model.ListResponse;
import com.sisyphus.simple.data.network.model.Post;
import com.sisyphus.spinach.core.INetPageTask;
import com.sisyphus.spinach.core.model.IPageResponse;
import com.sisyphus.spinach.core.model.IResponse;
import com.sisyphus.spinach.network.presenters.NetPageTask;
import com.sisyphus.spinach.ui.configs.IListTemplateProvider;
import com.sisyphus.spinach.ui.configs.impl.IPageTemplate;


import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import io.reactivex.rxjava3.core.Observable;

/**
 * 收藏帖子列表
 */
public class FavoritePostListActivity extends AppCompatActivity implements IListTemplateProvider<Post> {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(provider().view(this));
    }

    @Override
    public IPageTemplate<Post> provider() {
        return new SimpleAppActivityListTemplate<Post>() {

            @Override
            public INetPageTask.Presenter<Post, INetPageTask.View<Post>> presenter() {
                return new NetPageTask<Post>() {
                    @Override
                    public Observable<? extends IResponse<? extends IPageResponse<Post>>> execute(int page) {
                        return DataRepository.getInstance().postFavorite(page, ListResponse.PAGE_NUMBER);
                    }
                };
            }

            @Override
            public BaseQuickAdapter<Post, BaseViewHolder> adapter(RecyclerView recyclerView) {
                return new PostListAdapter();
            }

        };
    }

}
